<?php

/*
 * This file is part of PHP CS Fixer.
 *
 * (c) wangyt <wangtom365@gmail.com>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace App\Http\Controllers\Dict;

use App\Http\Controllers\BaseController;
use App\Models\Dict\DictRootsModel;
use App\Models\Dict\DictWordsModel;
use App\Models\Dict\DictSentencesModel;
use App\Models\Dict\DictLogsModel;
use Illuminate\Http\Request;

class DictSentencesController extends BaseController
{
    /**
     * 列表.
     *
     * @return string
     */
    public function index(Request $request)
    {
        return $this->showList($request);
    }

    /**
     * 关于我们.
     *
     * @param mixed $id
     *
     * @return \Illuminate\View\View
     */
    public function showDetail(Request $request, $id = 0)
    {
        $data = [];

        $result = (new PostModel())->getPostInfo($id);

        $data['seo'] = [
            'title' => $result['title'],
            'keywords' => '关键词',
            'description' => '',
        ];
        $data['detailData'] = $result;

        $data['categoryList'] = (new CategoryModel())->getPostCategoryList();

        return view('default.posts.postDetail', $data);
    }

    /**
     * 列表.
     *
     * @param mixed $category
     *
     * @return string
     */
    public function showList(Request $request, $category = '')
    {
        $page = $request->input('page', 0);
        $category = $request->input('category', '');
        $data = [];
        $where = [];
        if ($category) {
            $where['category'] = $category;
        }

        $result = (new PostModel())->getListWithPaginate($where, $page);
        if (empty($result)) {
            return '没有获取到数据.请确认URL是否正确.';
        }

        $data['categoryList'] = (new CategoryModel())->getPostCategoryList();

        $data['categoryCount'] = (new PostModel())->getListCountGroupByCategory();

        $data['listData'] = $result;

        return view('default.posts.postList', $data);
    }

}
